﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace ResponseMonitor
{
    public partial class NamingForm : Form
    {
        public string SubjectName = string.Empty;
        public string SessionName = string.Empty;

        private bool sessionFocused = false;

        public NamingForm()
        {
            InitializeComponent();
        }

        private void ultraButtonReset_Click(object sender, EventArgs e)
        {
            textBoxSubject.Text = string.Empty;
            textBoxSession.Text = string.Empty;
            textBoxSubject.Focus();
        }

        private void ultraButton1OK_Click(object sender, EventArgs e)
        {
            SubjectName = textBoxSubject.Text.Trim();
            SessionName = textBoxSession.Text.Trim();

            if (SubjectName.Length == 0)
            {
                MessageBox.Show("Subject CAN NOT be empty!");
                textBoxSubject.Focus();
                return;
            }
            if (SessionName.Length == 0)
            {
                MessageBox.Show("Session CAN NOT be empty!");
                textBoxSession.Focus();
                return;
            }

            this.DialogResult = DialogResult.OK;
            this.Close();
        }

        private void processNumberButton(int number)
        {
            if (sessionFocused)
                textBoxSession.Text += number.ToString();
            else
            {
                textBoxSubject.Focus();
                textBoxSubject.Text += number.ToString();
            }
        }

        private void ultraButton1_Click(object sender, EventArgs e)
        {
            processNumberButton(1);
        }

        private void ultraButton2_Click(object sender, EventArgs e)
        {
            processNumberButton(2);
        }

        private void ultraButton3_Click(object sender, EventArgs e)
        {
            processNumberButton(3);
        }

        private void ultraButton4_Click(object sender, EventArgs e)
        {
            processNumberButton(4);
        }

        private void ultraButton5_Click(object sender, EventArgs e)
        {
            processNumberButton(5);
        }

        private void ultraButton6_Click(object sender, EventArgs e)
        {
            processNumberButton(6);
        }

        private void ultraButton7_Click(object sender, EventArgs e)
        {
            processNumberButton(7);
        }

        private void ultraButton8_Click(object sender, EventArgs e)
        {
            processNumberButton(8);
        }

        private void ultraButton9_Click(object sender, EventArgs e)
        {
            processNumberButton(9);
        }

        private void ultraButton0_Click(object sender, EventArgs e)
        {
            processNumberButton(0);
        }

        private void NamingForm_Load(object sender, EventArgs e)
        {
            textBoxSubject.Focus();
            sessionFocused = false;
        }

        private void textBoxSubject_Enter(object sender, EventArgs e)
        {
            if (sessionFocused)
            {
                sessionFocused = false;
                textBoxSubject.Text = string.Empty;
            }
        }

        private void textBoxSession_Enter(object sender, EventArgs e)
        {
            if (!sessionFocused)
            {
                sessionFocused = true;
                textBoxSession.Text = string.Empty;
            }
        }
    }
}
